package thread.simulation;

/**
 * Title：
 * Description：
 * Created by Myth on 4/18/2017.
 */
public class MyNumber {
    private int number = -1;
    private boolean full = false; //初始为空

    public MyNumber() {
        this.number = number;
    }
    public MyNumber(int number) {
        this.number = number;
    }

    public synchronized void getNumber() {
        if (full) {
            full = false;
            System.out.println("取出数字：" + this.number);;
        }
    }

    public synchronized void setNumber(int number) {
        if (!full) {
            this.number = number; // [0-10)之间的随机数
            full = true;
            System.out.println("产生数字：" + this.number);
        }
    }
    @Override
    public String toString() {
        return  "number=" + number;
    }
}
